<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<!-- 通过状态模式，完成超级玛丽的跳跃、奔跑、射击、蹲下动作 -->
		
		<script type="text/javascript">
			var Marry = function(){
				var currentState={}
				var states={
					jump:function(){
						console.log('跳跃')
					},
					move:function(){
						console.log("移动")
					},
					shoot:function(){
						console.log("射击")
					},
					squat:function(){
						console.log("蹲下")
					}
				}
				var action ={
					changeState:function(){
						var arg = arguments;
						currentState={};
						if(arg.length){
							for(var i=0;i<arg.length;i++){
								currentState[arg[i]] = true
							}
							console.log('改变状态：')
						}
						return this;
					},
					run:function(){
						for(var key in currentState){
							currentState[key] && states[key]()
						}
						return this;
					}
				}
				return {
					changeState:action.changeState,
					run:action.run,
				}
			}
			var marry2 = new Marry();
			marry2.changeState('jump','shoot').run().changeState('squat','shoot').run()
		</script>
	</body>
</html>
